package com.wanpinghui.supplier.oauth;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;

import com.wanpinghui.supplier.common.BaseActivity;
import com.wanpinghui.wphlibrary.WPHSdk;
import com.wanpinghui.wphlibrary.model.oauth.OAuthService;
import com.yunshl.yunshllibrary.utils.TextUtil;

/***
 * 功能描述:
 * 作者:qiujialiu
 * 时间:2017/6/28
 ***/

public class LoginUtil {

    public static boolean isLogin() {
        return TextUtil.isNotEmpty(WPHSdk.getService(OAuthService.class).getToken());
    }

    public static boolean loginFilter(Context context) {
        if (isLogin()) {
            return true;
        } else {
            Intent intent = new Intent(context, LoginActivity.class);
            intent.putExtra("fromRequest", true);
            intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
            context.startActivity(intent);
            return false;
        }
    }

    public static boolean loginFilter(Activity context) {
        if (isLogin()) {
            return true;
        } else {
            Intent intent = new Intent(context, LoginActivity.class);
            intent.putExtra("fromRequest", true);
            intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
            context.startActivityForResult(intent, BaseActivity.REQUEST_LOGIN);
            return false;
        }
    }
}
